﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hotnet.Dal.NSDalPicture;
using Hotnet.Entity;
using Ninject.Core;
using System.Linq.Expressions;
using System.Data.Common;

namespace Hotnet.Biz.NSBizPicture
{
	public class BizPictureCategory : BaseBiz<PictureCategory>
	{

		private static DalPictureCategory dalPictureCategory = new DalPictureCategory();


		private BizPictureGroup _BizPictureGroup;
		private BizPictureGroup BizPictureGroup
		{
			get
			{
				if (_BizPictureGroup == null)
					_BizPictureGroup = new BizPictureGroup();
				return _BizPictureGroup;
			}
		}


		public BizPictureCategory() : base(dalPictureCategory) { }

		/// <summary>
		/// 删除图片分类,级联删除图片组,图片.
		/// </summary>
		/// <param name="categoryId"></param>
		public override void Delete(int categoryId)
		{
			//开始事务
			//using (DbTransaction tran = dalPictureCategory.BeginTransaction())
			//{
			//删除所有图片组
			BizPictureGroup.DeleteAllByCategoryId(categoryId);
			//删除图片分类
			base.Delete(categoryId);
			//    if (true)
			//        throw new Exception("我是故意的!");
			//    tran.Commit();
			//}
		}

		public PictureCategory[] ListCategroyIncludeGroup()
		{
			var categoryList = dalPictureCategory.List<int>(category => category.OrderNo ?? 0, false);
			foreach (var category in categoryList)
			{
				category.PictureGroups = BizPictureGroup.ListTop(category.CategoryID, 10);
			}
			return categoryList;
		}

		

	}
}